package com.rxyb.upms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rxyb.core.respone.R;
import com.rxyb.upms.db.bean.SysUser;
import com.rxyb.upms.db.dao.SysUserMapper;
import com.rxyb.upms.gate.enums.RspCode;
import com.rxyb.upms.gate.pojo.LoginReq;
import com.rxyb.upms.gate.pojo.LoginRsp;
import com.rxyb.upms.service.SysUserService;
import com.rxyb.upms.service.logic.SysUserLogic;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author YJH
 * @since 2020-05-26
 */
@Service
@Slf4j
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {


    private final SysUserLogic sysUserLogic;

    public SysUserServiceImpl(SysUserLogic sysUserLogic) {
        this.sysUserLogic = sysUserLogic;
    }


    /**
     * 用户登录
     *
     * @param req
     * @return
     */
    @Override
    public R<LoginRsp> login(LoginReq req) {
        log.debug("用户登录[{}]请求参数[{}]", req.getLoginName());
        SysUser user = sysUserLogic.findUserName(req.getLoginName());
        if (null == user) {
            log.warn("用户登录[{}]未查询到信息,", req.getLoginName());
            return R.failed(RspCode.U1000);
        }
        LoginRsp rsp = new LoginRsp();
        rsp.setLoginName(req.getLoginName());
        rsp.setLogPwd(user.getPassword());
        return R.ok(rsp);
    }
}
